#include "main.h"
#include "multi_button.h"
#include "bsp_gpio.h"
#include "My_button.h"
#include "bsp_usart.h"
#include "lvgl.h"
#include "gui_guider.h"
enum Button_IDs
{
	btn1_id,
	btn2_id,

	BUTTONS_NUM
};

struct Button btn1;
struct Button btn2;

static uint8_t read_button_GPIO(uint8_t button_id)
{
	// you can share the GPIO read function with multiple Buttons
	switch (button_id)
	{
	case btn1_id:
		return HAL_GPIO_ReadPin(KEY1_PORT, KEY1_PIN); // 确认按键
	case btn2_id:
		return HAL_GPIO_ReadPin(KEY2_PORT, KEY2_PIN); // 确认按键
	default:
		return 0;
	}
}

static void Buttons_Callback(void *button)
{
    if (get_button_event((struct Button *)button) != SINGLE_CLICK) return;

    if ((struct Button *)button == &btn1) {
        // 直接加载screen_1
        lv_scr_load(guider_ui.screen_1);
		
    } else if ((struct Button *)button == &btn2) {
        // 直接加载screen
        lv_scr_load(guider_ui.screen);
		

    }
}

void My_button_init_attach_start(void)
{

	button_init(&btn1, read_button_GPIO, 0, btn1_id);
	button_init(&btn2, read_button_GPIO, 0, btn2_id);
	button_attach(&btn1, SINGLE_CLICK, Buttons_Callback);
	button_attach(&btn2, SINGLE_CLICK, Buttons_Callback);

	button_start(&btn1);
	button_start(&btn2);
}
